package com.hzsai.controller;

import com.hzsai.pojo.User;
import com.hzsai.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * hzsai 2019/7/31
 * usage:
 **/
@Api(tags = "拦截器")
@RequestMapping("/interceptor")
@RestController
public class InterceptorController {

    @Autowired
    private UserService service;

    @ApiOperation(value = "拦截say")
    @PostMapping("/say")
    public Map<String, Object> testInterceptor() {
        Map<String, Object> retMap = new HashMap<String, Object>();
        retMap.put("say", "Hello");
        System.out.println("doing work");
        return retMap;
    }

    @ApiOperation(value = "RequestHeader", notes = "参数：id, 类型：long")
    @PostMapping("/rh")
    public User requestHeaderParam(@RequestHeader("id") Long id) throws SQLException {
        return service.selectUserById(id);
    }
}
